﻿@{
    Layout = "_Layout1.cshtml";

    string data = Request["data"];
    var doctorID = Request["ID"];

    var db = Database.Open("Clinic");
    //var query = "SELECT * FROM Appointment WHERE Doctor = @0 AND Termin = @1";
    var query = "SELECT * FROM Appointment WHERE Doctor = @0";
    var singleQuery = "SELECT * FROM Doctor WHERE ID = @0";

    
    var doctor = db.QuerySingle(singleQuery, doctorID);
	
	string workStart = doctor.WorkingTimeStart.Hour + ":" + doctor.WorkingTimeStart.Minute.ToString("00");
    string workStop = doctor.WorkingTimeStop.Hour + ":" + doctor.WorkingTimeStop.Minute.ToString("00");


    query =  "SELECT * FROM Appointment WHERE Doctor = @0 AND Termin BETWEEN '" + data + " 00:00' AND '" + data + " 23:00'";
    var appointments = db.Query(query, doctorID);

   

    int appsPerDay = ((doctor.WorkingTimeStop.Hour * 60 + doctor.WorkingTimeStop.Minute) - (doctor.WorkingTimeStart.Hour * 60 + doctor.WorkingTimeStart.Minute ))/15;

}


<article id="tables">
@{
string minutes = "";
bool terminOccupied = false;
int hours = doctor.WorkingTimeStart.Hour;

    for (int i = 0 ; i < appsPerDay; i++)
    {
        terminOccupied = false;
        minutes = ((i%4)*15).ToString("00");
        <text>@hours:@minutes</text>
        

   
    foreach (var f in appointments)
    {

     

        if (hours == f.Termin.Hour & minutes == f.Termin.Minute.ToString("00"))
        {
            <text>---------------- @f.Patient</text>
            terminOccupied  = true;
        }

     

    }
    if (!terminOccupied)
    {
        <text><a href="Register.cshtml?ID=@doctorID&data=@data&h=@hours&m=@minutes">Zarejestruj! Zamień to na pole + whitespace</a></text>
        
    }

        <text><br></text>

        if (i%4 == 3)
        {
            hours +=1;
        }

    }

    
}
</article>

